import axios from "axios";
axios.interceptors.request.use(config => {
    config.headers['Authorization'] = 'Bearer ' + localStorage.token;
    return config;
})

axios.interceptors.response.use(response => {
    return response;
}, error => {
    if (error.response.status == 401) {
        window.location.href = "/login";
        alert("请登录");
    }
    return Promise.reject(error.response.data);
});

// axios.defaults.headers.common['Authorization'] = 'Bearer ' + localStorage.token;

export default axios;
export const url = "/api";